﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Shapes;
using System.Drawing;
using Silvermoon.Images;
using Silvermoon.Core;
using Silvermoon.OpenGL;
using Silvermoon.Windows;
using Silvermoon.UI;

namespace Silvermoon.Controls
{
    public class ToolbarButton : ContentButton
    {

        private static new readonly VisualStateGroup OpacityDisabledEnabledGroup = new VisualStateGroup(
        new VisualState(VState.Enabled,
            new IntTransition
            {
                To = 255,
                Duration = 300,
                Property = Control.OpacityProperty,
                Tracking = TrackMode.Keep
            }
            ),

        new VisualState(VState.Disabled,
            new IntTransition
            {
                To = 64,
                Duration = 300,
                Property = Control.OpacityProperty,
                Tracking = TrackMode.Keep
            }
    )
        );

        static ToolbarButton()
        {
            VisualStateManager buttonManager = new VisualStateManager(
                ToolbarButton.OpacityDisabledEnabledGroup,
                new VisualStateGroup(
                   new VisualState(VState.Normal) { Duration = 500 },
                    new VisualState(VState.Pressed,
                        new ScaleTransition
                        {
                            To = new ScaleTransform(0.91f, 0.91f, 1f),
                            Duration = 5,
                        }
                    )
                )
             );

            VisualStateManager.RegisterClassManager(typeof(ToolbarButton), buttonManager);
        }

        public ToolbarButton()
            : base()
        {
            TextColor = Color.Empty;
        }

        public ToolbarButton(Shape content, EventHandler<TapEventArgs> onTap)
            : base()
        {
            this.Content = content;
            this.Tap += onTap;
        }


        public ToolbarButton(Texture content, ICommand command)
            : base()
        {
            this.Content = content;
            this.Command = command;
        }

        public ToolbarButton(Shape content)
            : base()
        {
            this.Content = content;
        }

        public ToolbarButton(Shape content, ICommand command)
            : base()
        {
            this.Content = content;
            this.Command = command;
        }

        public override Color Color
        {
            get
            {
                return TextColor;
            }
            set
            {
            }
        }

        protected override Shape CreateDefaultBackground()
        {
            return new CircleShape();
        }


        class CircleShape : ColorShape
        {
            protected override Texture TextureCore { get { return SysImages.Circle; } }
            protected override Color GetDefaultColor()
            {
                return Color.Empty;
            }
            protected override RenderStyle StyleCore { get { return RenderStyle.Simple; } }

            protected override Color GetShapeColor()
            {
                Color c = Color;
                if (!c.IsEmpty) return c;
                return Screen.Current.Renderer.TextColor;
            }


            protected override Shape CreateClone()
            {
                return new CircleShape();
            }
        }

    }
}
